package com.mango.ch02;

import java.io.IOException;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.mango.Tools.DateUtils;

public class SparkSortMapper extends Mapper<LongWritable, Text, CompositeKey, NaturalValue> {

	@Override
	protected void map(LongWritable key, Text value,
			Mapper<LongWritable, Text, CompositeKey, NaturalValue>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		String[] datas = value.toString().split(",");
		Text stockName = new Text(datas[0]);
		LongWritable time = new LongWritable(DateUtils.dateToLong(datas[1]));
		DoubleWritable price = new DoubleWritable(Double.valueOf(datas[2]));
		CompositeKey cpsKey = new CompositeKey();
		cpsKey.setStockSymbol(stockName);
		cpsKey.setTimestamp(time);
		NaturalValue nValue = new NaturalValue();
		nValue.setPrice(price);
		nValue.setTimestamp(time);
		context.write(cpsKey, nValue);
	}



}
